<?php
/**
 * Created by phpstorm.
 * User: WML
 * Date: 2019/8/5 0005
 * Time: 17:23
 */
namespace app\index\controller;
use app\index\model\Users;
use think\Controller;
use think\facade\Session;
class Login extends Controller
{
    public function index(){
        if(request()->post()){
            $row = request()->param();
            $user_data = Users::where('username',$row['username'])->find();
            if(empty($user_data))return errorResponse(['code' => -1,'msg' => '该用户不存在']);
            if($user_data['password'] != $row['password'])return errorResponse(['code' => -2,'msg' => '密码不正确']);
            session::set("user_id",$user_data['id']);
            return successResponse();
        }
        return view("index");
    }
}